Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls


Public Enum TileTemplate

    app = 1
    square_text = 2
    square_text_tilesquareblock = 3
    square_image = 4
    squarepeek = 5

    wide_app = 6
    wide_text = 7
    wide_image = 8
    wide_image_collection = 9
    wide_imagetext = 10
    wide_imagetext_wideimage = 11

    tilewideblockandtext02 = 12

End Enum


<DefaultProperty("Text"), ToolboxData("<{0}:Tile runat=server></{0}:Tile>")> _
Partial Public Class Tile
    Inherits WebControl

    <Bindable(True), Category("Appearance"), DefaultValue(""), Localizable(True)> Property Text() As String
        Get
            Dim s As String = CStr(ViewState("Text"))
            If s Is Nothing Then
                Return String.Empty
            Else
                Return s
            End If
        End Get

        Set(ByVal Value As String)
            ViewState("Text") = Value
        End Set
    End Property

    Private _tiletemplate As String
    Private _tilebgcolor As String
    Private _tileurl As String
    Private _tileicon As String
    Private _tileimage As String
    Private _tileapplabel As String
    Private _tileappcount As String
    Private _tiletext As String
    Private _tiletextheader As String
    Private _tiletextbig As String
    Private _iterations As Integer = 1

    Public Property TileTemplate() As TileTemplate
        Get
            Return _tiletemplate
        End Get
        Set(ByVal value As TileTemplate)
            _tiletemplate = value
        End Set
    End Property
    Public Property TileBgcolor As String
        Get
            Return _tilebgcolor
        End Get
        Set(ByVal value As String)
            _tilebgcolor = value
        End Set
    End Property

    Public Property TileURL() As String
        Get
            Return _tileurl
        End Get
        Set(ByVal value As String)
            _tileurl = value
        End Set
    End Property
    Public Property TileIcon() As String
        Get
            Return _tileicon
        End Get
        Set(ByVal value As String)
            _tileicon = value
        End Set
    End Property
    Public Property TileImage() As String
        Get
            Return _tileimage
        End Get
        Set(ByVal value As String)
            _tileimage = value
        End Set
    End Property
    Public Property TileAppLabel() As String
        Get
            Return _tileapplabel
        End Get
        Set(ByVal value As String)
            _tileapplabel = value
        End Set
    End Property
    Public Property TileAppCount() As String
        Get
            Return _tileappcount
        End Get
        Set(ByVal value As String)
            _tileappcount = value
        End Set
    End Property
    Public Property TileText() As String
        Get
            Return _tiletext
        End Get
        Set(ByVal value As String)
            _tiletext = value
        End Set
    End Property
    Public Property TileTextHeader() As String
        Get
            Return _tiletextheader
        End Get
        Set(ByVal value As String)
            _tiletextheader = value
        End Set
    End Property
    Public Property TileTextBig() As String
        Get
            Return _tiletextbig
        End Get
        Set(ByVal value As String)
            _tiletextbig = value
        End Set
    End Property

    Public Property Iterations() As Integer
        Get
            Return _iterations
        End Get
        Set(ByVal value As Integer)
            _iterations = value
        End Set
    End Property

    Protected Overrides ReadOnly Property TagKey() As HtmlTextWriterTag
        Get
            Return HtmlTextWriterTag.A
        End Get
    End Property

    Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

        Dim strClass As String = "tile "

        Select Case _tiletemplate
            Case TileTemplate.app
                strClass = strClass & "app " & "bg-color-" & _tilebgcolor
            Case TileTemplate.square_text
                strClass = strClass & "square text "
            Case TileTemplate.square_text_tilesquareblock
                strClass = strClass & "square text tilesquareblock "
            Case TileTemplate.square_image
                strClass = strClass & "square image "
            Case TileTemplate.squarepeek
                strClass = strClass & "squarepeek "
            Case TileTemplate.wide_app
                strClass = strClass & "wide app " & "bg-color-" & _tilebgcolor
            Case TileTemplate.wide_text
                strClass = strClass & "wide text "
            Case TileTemplate.wide_image
                strClass = strClass & "wide image "
            Case TileTemplate.wide_image_collection
                strClass = strClass & "wide image collection "
            Case TileTemplate.wide_imagetext
                strClass = strClass & "wide imagetext "
            Case TileTemplate.wide_imagetext_wideimage
                strClass = strClass & "wide imagetext wideimage "
            Case TileTemplate.tilewideblockandtext02
                strClass = strClass & "tilewideblockandtext02 "

        End Select

        writer.AddAttribute(HtmlTextWriterAttribute.Href, Me.TileURL, True)
        writer.AddAttribute(HtmlTextWriterAttribute.Class, strClass, True)
        writer.RenderBeginTag(HtmlTextWriterTag.A)
        writer.WriteLine()
        writer.Indent += 1

        Select Case _tiletemplate

            Case TileTemplate.app, TileTemplate.wide_app
                If Me.TileImage <> String.Empty Or Me.TileIcon <> String.Empty Then

                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "image-wrapper", True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Div)

                    If Me.TileImage <> String.Empty Then
                        writer.AddAttribute(HtmlTextWriterAttribute.Src, Me.TileImage, True)
                        writer.AddAttribute(HtmlTextWriterAttribute.Alt, Me.TileAppLabel, True)
                        writer.RenderBeginTag(HtmlTextWriterTag.Img)
                        writer.RenderEndTag()
                    End If

                    If Me.TileIcon <> String.Empty Then
                        writer.AddAttribute(HtmlTextWriterAttribute.Class, "icon " & Me.TileIcon, True)
                        writer.RenderBeginTag(HtmlTextWriterTag.Span)
                        writer.RenderEndTag()
                    End If

                    writer.RenderEndTag() ' div

                End If
                If Me.TileAppLabel <> String.Empty Then
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "app-label", True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Div)
                    writer.Write(Me.TileAppLabel)
                    writer.RenderEndTag() ' div
                End If

                If Me.TileAppCount <> String.Empty Then
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "app-count", True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Div)
                    writer.Write(Me.TileAppCount)
                    writer.RenderEndTag() ' div
                End If

            Case TileTemplate.square_image, TileTemplate.wide_image

                If Me.TileImage <> String.Empty Then
                    writer.AddAttribute(HtmlTextWriterAttribute.Src, Me.TileImage, True)
                    writer.AddAttribute(HtmlTextWriterAttribute.Alt, Me.TileAppLabel, True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Img)
                    writer.RenderEndTag() 'img
                End If

            Case TileTemplate.square_text, TileTemplate.square_text_tilesquareblock

                If Me.TileTextHeader <> String.Empty Then
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "text-header", True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Div)
                    writer.Write(Me.TileTextHeader)
                    writer.RenderEndTag() ' div
                End If
                If Me.TileTextBig <> String.Empty Then
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "text-big", True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Div)
                    writer.Write(Me.TileTextBig)
                    writer.RenderEndTag() ' div
                End If
                If Me.TileText <> String.Empty Then
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "text5", True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Div)
                    writer.Write(Me.TileText)
                    writer.RenderEndTag() ' div
                End If
                If Me.TileAppCount <> String.Empty Then
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "app-count", True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Div)
                    writer.Write(Me.TileAppCount)
                    writer.RenderEndTag() ' div
                End If

            Case TileTemplate.squarepeek

                If Me.TileImage <> String.Empty Then
                    writer.AddAttribute(HtmlTextWriterAttribute.Src, Me.TileImage, True)
                    writer.AddAttribute(HtmlTextWriterAttribute.Alt, Me.TileAppLabel, True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Img)
                    writer.RenderEndTag() 'img
                End If

                If Me.TileTextHeader <> String.Empty Or Me.TileText <> String.Empty Then
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "text-inner", True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Div)

                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "text-header", True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Div)
                    writer.Write(Me.TileTextHeader)
                    writer.RenderEndTag() ' div

                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "text8", True)
                    writer.RenderBeginTag(HtmlTextWriterTag.Div)
                    writer.Write(Me.TileText)
                    writer.RenderEndTag() ' div
                    writer.RenderEndTag() ' div
                End If

        End Select

        writer.WriteLine()
        writer.Indent -= 1
        writer.RenderEndTag() 'a

        Dim i As Integer
        For i = 0 To _iterations - 1
            'output.Write("<" & HtmlSize & ">" & _message & "</" & HtmlSize & ">")
            'output.Write("<div class='image-wrapper'>" & _message & "</div>")
        Next

    End Sub


End Class
